# 打印 "Hello World" 到控制台
# print("Hello World")
#!/usr/bin/python3
 
# tup = ('Google', 'Runoob', 1997, 2000)
 
# print (tup)
# del tup
# print ("删除后的元组 tup : ")
# print (tup)
# tup =(1,2,3,4,5)
# len(tup)
# max(tup)
# print("tup最大值为：",(max(tup)))
# student = {"name": "John", "age": 30, "city": "New York"}
# print("学生信息如下：" '\t'+ "名字："+str(student["name"])+"  年龄："+str(student["age"])+" 城市："+str(student["city"]))   # 输出学生信息
# if 'name' in student:
#     print("1")
    
# else:
#     print("0")
# set1 = {1, 2, 3, 4, 5}
# set1.add(6)
# print(set1)
# set1.discard(8)
# if 8 in set1:
#     print("8在集合中")
# else:
#         print("8不在集合中")    
#!/usr/bin/python3
 
# age = int(input("请输入你家狗狗的年龄: "))
# print("")
# if age <= 0:
#     print("你是在逗我吧!")
# elif age == 1:
#     print("相当于 14 岁的人。")
# elif age == 2:
#     print("相当于 22 岁的人。")
# elif age > 2:
#     human = 22 + (age -2)*5
#     print("对应人类年龄: ", human)
 
# ### 退出提示
# input("点击 enter 键退出")
# tup1=([1,2,3,4,5])
# number2=int(input("请输入你猜的数字："))
# if number2 == tup1[2]:
#     print("恭喜你，你猜对了！")
# else:
#     print("很遗憾，你错了！")
# my_list = ['google', 'runoob', 'taobao']
# for i in my_list:  
#     print(i)
# def change(a):
#     print(id(a))   # 指向的是同一个对象
#     a=10
#     print(id(a))   # 一个新对象
 
# a=1
# print(id(a))
# change(a)
# def repeat(num_times):
#     def decorator(func):
#         def wrapper(*args, **kwargs):
#             for _ in range(num_times):
#                 func(*args, **kwargs)
#         return wrapper
#     return decorator

# @repeat(3)
# def say_hello():
#     print("Hello!")

# say_hello()   # 输出 Hello! 三次
# f=open('/tmp/foo.txt', 'w')
# f = open('/tmp/foo.txt', 'rb+')
# f.write(b'0123456789abcdef')

# f.seek(5)     # 移动到文件的第六个字节

# f.read(1)
# f.seek(-3, 2) # 移动到文件的倒数第三字节
# f.read(1)
# f.close()
# 创建空文件（如果文件已存在会被清空）
# with open('example.txt', 'w') as f:
#     pass  # 不写入任何内容
# f = open('example.txt', 'rb+')
# f.write(b'0123456789abcdef')
# f.seek(5)     # 移动到文件的第六个字节
# print(f.read(1))
# f.read(1)
# f.seek(-3, 2) # 移动到文件的倒数第三字节
# f.read(1)
# print(f.read(1))
# import pickle

# # 定义一个字典对象 data1，包含三个键值对
# data1 = {
#     'a': [1.0, 2.0, 3.0],  # 键 'a' 对应一个包含浮点数的列表
#     'b': ['abc', 'def', 'ghi'],  # 键 'b' 对应一个包含字符串的列表
#     'c': [True, False, True]  # 键 'c' 对应一个包含布尔值的列表
# }

# # 定义一个自引用列表 selfref_list
# selfref_list = [1, 2, 3]  # 初始列表包含三个整数
# selfref_list.append(selfref_list)  # 将列表自身添加到列表的末尾，形成自引用

# # 以二进制写模式打开文件 'data.pkl'，如果文件不存在则创建新文件
# output = open('data.pkl', 'wb')

# # 将字典 data1 序列化并写入到文件 'data.pkl' 中
# pickle.dump(data1, output)

# # 将自引用列表 selfref_list 序列化并写入到文件 'data.pkl' 中，使用最高版本的协议
# pickle.dump(selfref_list, output, -1)

# # 关闭文件，确保所有数据都被写入并且文件资源被正确释放
# output.close()
#!/usr/bin/python3
# import pprint, pickle

# 使用pickle模块从文件中重构Python对象
# pkl_file = open('data.pkl', 'rb')  # 以二进制读模式打开文件 'data.pkl'

# data1 = pickle.load(pkl_file)  # 从文件 'data.pkl' 中反序列化并加载第一个对象
# pprint.pprint(data1)  # 使用 pprint 模块以更易读的格式打印第一个对象

# data2 = pickle.load(pkl_file)  # 从文件 'data.pkl' 中反序列化并加载第二个对象
# pprint.pprint(data2)  # 使用 pprint 模块以更易读的格式打印第二个对象

# pkl_file.close()  # 关闭文件，确保文件资源被正确释放

# def my_decorator(func):
#     def wrapper(*args, **kwargs):
#         print("Before calling the function")
#         result = func(*args, **kwargs)
#         print("After calling the function")
#         return result
#     return wrapper
# names =['Bob', 'Alice', 'Tom']  
# new_names = [name.upper() for name in names if len(name) > 3] 
# print(new_names)
# multiples = [i for i in range(1,31) if i % 3 == 0]
# print(multiples)
# setnew = {i**2 for i in (1,2,3)}
# print(setnew)
# list =[1,2,3,4,5,6,7,8,9,10]
# it = iter(list)    
# for i in it:
#     print (i,end='')
# import sys
# list1 = [1, 2, 3, 4, 5]
# it = iter(list1)   
# while True:
#     try:
#         print(next(it), end=' ')
#     except StopIteration:
# #         sys.exit()  
# class MyNumbers:
#   def __iter__(self):
#     self.a = 1
#     return self
 
#   def __next__(self):
#     if self.a <= 20:
#       x = self.a
#       self.a += 1
#       return x
#     else:
#         raise StopIteration
 
# myclass = MyNumbers()
# myiter = iter(myclass)
# for x in myiter:
# #   print(x)
# def Max(a,b):
#     if a>b:
#         return a
#     else:
#         return b
# a = input("请输入第一个数字：")
# b = input("请输入第二个数字：")
# print("最大值是：",Max(int(a),int(b)))
# def area(width, height):
#     return width * height
# def print_welcome(name):
#     print("Welcome,", name)
# print_welcome("John")
# width =input("请输入矩形的宽度：")
# height=input("请输入矩形的高度：")
# print("矩形的面积是：", area(int(width), int(height)))
# def print_string(str):
#     print(str)
#     return
# userinput = input("请输入：")
# print_string(userinput)

# def myfunc(n):
#   return lambda a : a * n
 
# mydoubler = myfunc(2)
# mytripler = myfunc(3)
 
# print(mydoubler(11))
# print(mytripler(11))
# f =lambda:"hello world"
# print(f())
# numbers = [1, 2, 3, 4, 5]
# squares = list(map(lambda x: x**2, numbers))
# print(squares)

# python装饰器

# @staticmethod #定义静态方法
# def decorator_function(original_function):
#     def wrapper(*args,**kwargs):
#         before_call_code() # type: ignore
#         result =original_function(*args,**kwargs)
#         after_call_code() # type: ignore
#         return result
#     return wrapper
# @decorator_function
# def target_function(arg1,arg2):
#     pass
# @classmethod  # 定义类方法
# def repeat(num_times):
#     def decorator(func):
#         def wrapper(*args, **kwargs):
#             for _ in range(num_times):
#                 func(*args, **kwargs)
#         return wrapper
#     return decorator

# @repeat(3)
# def say_hello():
#     print("Hello!")

# say_hello()
# def my_decorator(cls):
#     class Wrapper:
#         def __init__(self, *args, **kwargs):
#             self.wrapped = cls(*args, **kwargs)

#         def display(self):
#             print("在类方法之前执行")
#             self.wrapped.display()
#             print("在类方法之后执行")
#     return Wrapper

# @my_decorator
# class MyClass:
#     def display(self):
#         print("这是 MyClass 的 display 方法")

# obj = MyClass()
# obj.display()

# class MyClass:
#     @staticmethod
#     def static_method():
#         # 静态方法，不依赖于实例或类本身，直接通过类名调用
#         print("This is a static method.")

#     @classmethod
#     def class_method(cls):
#         # 类方法，通过类名调用，第一个参数是类自身
#         print(f"This is a class method of {cls.__name__}.")

#     @property
#     def name(self):
#         # 获取属性 name 的值
#         return self._name

#     @name.setter
#     def name(self, value):
#         # 设置属性 name 的值
#         self._name = value

# # 使用
# # 调用静态方法
# MyClass.static_method()
# # 调用类方法
# MyClass.class_method()

# # 创建类的实例
# obj = MyClass()
# # 设置实例属性 name
# obj.name = "Alice"
# # 获取并打印实例属性 name
# print(obj.name)
# def decorator1(func):
#     def wrapper():
#         print("Decorator 1")
#         func()
#     return wrapper

# def decorator2(func):
#     def wrapper():
#         print("Decorator 2")
#         func()
#     return wrapper

# @decorator1
# @decorator2
# def say_hello():
#     print("Hello!")

# say_hello()
#!/usr/bin/python3
# 文件名: using_sys.py
a = input("请输入你的数字：")
int_list1= [1,2,3,4,5,6,7,8,9,10]
if int(a) in int_list1:
    print("你输入的数字在列表中")
else:    
    print("你输入的数字不在列表中")
